#ifndef MANGOS_OBJECTLIFETIME_H
#define MANGOS_OBJECTLIFETIME_H

#include <stdexcept>
#include "Platform/Define.h"

typedef void (* Destroyer)(void);

namespace MaNGOS
{
void MANGOS_DLL_SPEC at_exit(void (*func)());

template<class T>
class MANGOS_DLL_DECL ObjectLifeTime
{
    public:

        static void ScheduleCall(void (*destroyer)())
        {
            at_exit(destroyer);
        }

        DECLSPEC_NORETURN static void OnDeadReference() ATTR_NORETURN;
};

template <class T>
void ObjectLifeTime<T>::OnDeadReference()           // We don't handle Dead Reference for now
{
    throw std::runtime_error("Dead Reference");
}
}

#endif
